const hope = require("hope");

const { readdir } = require("fs");

const { join } = require("path");

hope.registerSrv("hopeUtils", function () {
	this.__init = function () {
		// 读取libs下的文件夹作为第一层级调用
		return new Promise((resolve, reject) => {
			const rootDir = join(__dirname, "./lib/");

			readdir(rootDir, (err, files) => {
				if (err) return reject(err);

				files &&
					files.length &&
					files.forEach(file => {
						let name = file.replace(/-(\w)/g, (all, letter) => letter.toUpperCase());

						this[name] = require(join(rootDir, file, "index.js"));
					});

				resolve();
			});
		});
	};
});
